<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Grid\SwitchGridView;
use App\Admin\Repositories\Image;
use App\Models\Product;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;

class TagSearchController
{

    public function index(Content $content)
    {
        return $content
            ->title('标签搜索')
            ->description('选择标签返回可是效果')
            ->body($this->grid());
    }

    protected function grid()
    {
        return Grid::make(new Product(), function (Grid $grid) {
            $grid->view('admin.custom');

            $grid->disableCreateButton();

            $grid->column('id', __('ID'));

            $grid->column('product_name');
            $grid->column('master_img')->image();
            $grid->column('customer_number');
            $grid->column('created_at');
            $grid->column('updated_at');

            /**
             * 搜索框
             */
            $grid->filter(function (Grid\Filter $filter) {
//                $filter->where('labels',function ($query){
//                    $query->whereJsonContains ('labels',"{$this->input}");
//                })->checkbox(Product::$tag);
                $filter->where('labels',function ($query){
                    $query->whereJsonContains ('labels',$this->input);
                })->checkbox(Product::$tag);
            });
            $grid->disableDeleteButton();
        });
    }
}
